package com.hfzy.ihk.web.freeswitchManage.conf;


import com.hfzy.ihk.web.freeswitchManage.websocket.swx.SwxWebSocketHandshakeInterceptor;
import com.hfzy.ihk.web.freeswitchManage.websocket.swx.handler.SwxWebSocketHandler;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
import org.springframework.web.socket.server.standard.ServletServerContainerFactoryBean;

/**
 * Created by Administrator on 2018/7/31.
 *
 * @author wws
 */
@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {



    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {


        //电信SWX
        registry.addHandler(swxWebSocketHandler(), "/swx/connect")
                .addInterceptors(new SwxWebSocketHandshakeInterceptor())
                .setAllowedOrigins("*");

    }


    @Bean
    public SwxWebSocketHandler swxWebSocketHandler(){
        return new SwxWebSocketHandler();
    }


    @Bean
    public ServletServerContainerFactoryBean createWebSocketContainer() {
        ServletServerContainerFactoryBean container = new ServletServerContainerFactoryBean();
        container.setMaxTextMessageBufferSize(8192);
        container.setMaxBinaryMessageBufferSize(8192);
        container.setAsyncSendTimeout(5000L);
        container.setMaxSessionIdleTimeout(1800000L);
        return container;
    }
}
